home *** CD-ROM | disk | FTP | other *** search
- #include <A4Stuff.h>
-
- typedef struct {
- WindowPeek theWindow;
- short varCode;
- short whichPart;
- } DeviceLoopData;
-
- #define kDragWidth 9
- #define kCloseBoxSize 5
- #define kCloseBoxYMargin 4
- #define kCloseBoxXMargin 2
-
- #define kFrameColor 1
- #define kDragBarColor 5
- #define kCloseBoxColor 6
-
- #define kDragOnLeftVarCode 1
-
- RGBColor gBlackColor = { 0x0000, 0x0000, 0x0000 };
- AuxWinHandle gAuxInfo;
- Boolean gBlackAndWhite;
-
- pascal void myDrawDragBarProc (short depth, short flags, GDHandle device, DeviceLoopData *data);
- pascal long main (short varCode, WindowPeek theWindow, short message, long param);
- void getDragRect (short varCode, WindowPeek window, Rect *r);
- void getCloseRect (short varCode, WindowPeek window, Rect *r);
- void calcRgns (short varCode, WindowPeek theWindow);
- void drawCloseBox (short varCode, WindowPeek theWindow, Boolean invert);
- pascal void myDrawDragBarProc (short depth, short flags, GDHandle device, DeviceLoopData *data);
- void drawDragBar (short varCode, WindowPeek theWindow, short whichPart);
- void doDraw (short varCode, WindowPeek theWindow, short whichPart);
- short doHit (short varCode, WindowPeek theWindow, Point where);
- void makeBorder (short varCode, Rect* r);
-
- #define kZigSize 3
-
- void makeBorder (short varCode, Rect* r)
- {
- Rect bounds = *r;
- Point start, zigFinish, finish;
- short height, slop;
- short horizontalOffset;
-
- // Because I hate the way quickdraw lines hang down and to the right
- --bounds.bottom;
- --bounds.right;
-
- if (varCode & kDragOnLeftVarCode) {
- finish.h = bounds.right;
- finish.v = bounds.top;
- MoveTo (bounds.right, bounds.top);
- LineTo (bounds.left, bounds.top);
- LineTo (bounds.left, bounds.bottom);
- LineTo (bounds.right, bounds.bottom);
- start.h = bounds.right;
- start.v = bounds.bottom;
- horizontalOffset = -kZigSize;
- } else {
- finish.h = bounds.left;
- finish.v = bounds.top;
- MoveTo (bounds.left, bounds.top);
- LineTo (bounds.right, bounds.top);
- LineTo (bounds.right, bounds.bottom);
- LineTo (bounds.left, bounds.bottom);
- start.h = bounds.left;
- start.v = bounds.bottom;
- horizontalOffset = kZigSize;
- }
-
- height = start.v - finish.v;
- slop = height % (kZigSize * 2);
-
- start.v -= slop / 2;
- zigFinish.h = finish.h;
- zigFinish.v = finish.v + (slop - (slop / 2));
- LineTo (start.h, start.v);
-
- // ZigZag from start to finish
- while (start.v > zigFinish.v) {
- LineTo (start.h += horizontalOffset, start.v -= kZigSize);
- horizontalOffset *= -1;
- }
-
- LineTo (finish.h, finish.v);
- }
-
-
- void getDragRect (short varCode, WindowPeek window, Rect *r)
- {
- Rect windowRect;
-
- windowRect = (*window -> contRgn) -> rgnBBox;
-
- r -> top = windowRect.top;
- r -> bottom = windowRect.bottom;
-
- if (varCode & kDragOnLeftVarCode)
- r -> left = windowRect.left - kDragWidth - 1;
- else
- r -> left = windowRect.right + 1;
-
- r -> right = r -> left + kDragWidth;
- }
-
- void getCloseRect (short varCode, WindowPeek window, Rect *r)
-
- {
- Rect dragRect;
-
- getDragRect (varCode, window, &dragRect);
-
- if (window -> goAwayFlag) {
- r -> top = dragRect.top + kCloseBoxYMargin;
- r -> left = dragRect.left + kCloseBoxXMargin;
- r -> bottom = r -> top + kCloseBoxSize;
- r -> right = r -> left + kCloseBoxSize;
- } else {
- r -> top = 0;
- r -> left = 0;
- r -> bottom = 0;
- r -> right = 0;
- }
- }
-
- void calcRgns (short varCode, WindowPeek theWindow)
-
- {
- Rect r;
- Rect dragRect;
- RgnHandle dragRgn;
-
- RgnHandle tempRgn1 = NewRgn (), tempRgn2 = NewRgn ();
-
- r = theWindow -> port.portRect;
- OffsetRect (&r, -theWindow -> port.portBits.bounds.left,
- -theWindow -> port.portBits.bounds.top);
-
- OpenRgn ();
- makeBorder (varCode, &r);
- CloseRgn (tempRgn1);
-
- InsetRect (&r, -1, -1);
- OpenRgn ();
- makeBorder (varCode, &r);
- CloseRgn (tempRgn2);
-
- CopyRgn (tempRgn1, theWindow -> contRgn);
- DiffRgn (tempRgn2, tempRgn1, tempRgn2);
- CopyRgn (tempRgn2, theWindow -> strucRgn);
-
- dragRgn = NewRgn ();
- getDragRect (varCode, theWindow, &dragRect);
- InsetRect (&dragRect, -1, -1);
- RectRgn (dragRgn, &dragRect);
-
- UnionRgn (dragRgn, theWindow -> strucRgn, theWindow -> strucRgn);
- UnionRgn (theWindow -> strucRgn, theWindow -> contRgn, theWindow -> strucRgn);
-
-
- DisposeRgn (dragRgn);
- DisposeRgn (tempRgn1);
- DisposeRgn (tempRgn2);
- }
-
- void drawCloseBox (short varCode, WindowPeek theWindow, Boolean invert)
-
- {
- Rect r;
- RGBColor oldBack, c = (**(**gAuxInfo).awCTable).ctTable [kFrameColor].rgb;
- RGBForeColor (&c);
-
- if (!theWindow -> goAwayFlag)
- return;
-
- getCloseRect (varCode, theWindow, &r);
-
- FrameRect (&r);
- InsetRect (&r, 1, 1);
-
- if (invert)
- InvertRect (&r);
- else
- EraseRect (&r);
-
- }
-
- pascal void myDrawDragBarProc (short depth, short flags, GDHandle device, DeviceLoopData *data)
- {
- EnterCodeResource ();
-
- Rect dragRect;
- RGBColor oldFore, oldBack;
-
- GetForeColor (&oldFore);
- GetBackColor (&oldBack);
-
- RGBColor c = (**(**gAuxInfo).awCTable).ctTable [kDragBarColor].rgb;
- RGBBackColor (&c);
-
- getDragRect (data -> varCode, data -> theWindow, &dragRect);
- EraseRect (&dragRect);
- MoveTo (dragRect.left, dragRect.top);
- drawCloseBox (data -> varCode, data -> theWindow, false);
-
- RGBForeColor (&oldFore);
- RGBBackColor (&oldBack);
-
- SetA4 (oldA4);
- }
-
- void drawDragBar (short varCode, WindowPeek theWindow, short whichPart)
-
- {
- DeviceLoopData data;
-
- data.theWindow = theWindow;
- data.varCode = varCode;
- data.whichPart = whichPart;
- DeviceLoop (GetGrayRgn (), (DeviceLoopDrawingUPP) myDrawDragBarProc,
- (long) &data, singleDevices);
- }
-
- void doDraw (short varCode, WindowPeek theWindow, short whichPart)
-
- {
- GrafPtr curPort;
- RgnHandle clipSave;
- RgnHandle dragContent;
- Rect r;
-
- if (!theWindow -> visible)
- return;
-
- GetAuxWin ((WindowPtr) theWindow, &gAuxInfo);
-
- clipSave = NewRgn ();
- GetPort (&curPort);
- CopyRgn (curPort -> clipRgn, clipSave);
- DiffRgn (curPort -> clipRgn, theWindow -> contRgn, curPort -> clipRgn);
-
- dragContent = NewRgn ();
- getDragRect (varCode, theWindow, &r);
- RectRgn (dragContent, &r);
- DiffRgn (curPort -> clipRgn, dragContent, curPort -> clipRgn);
-
- RGBColor saveColor;
- RGBColor frameColor;
-
- frameColor = (**(**gAuxInfo).awCTable).ctTable [kFrameColor].rgb;
-
- GetForeColor (&saveColor);
- RGBForeColor (&frameColor);
-
- PaintRgn (theWindow -> strucRgn);
-
- RGBForeColor (&saveColor);
-
- CopyRgn (clipSave, curPort -> clipRgn);
- drawDragBar (varCode, theWindow, whichPart);
-
- DisposeRgn (clipSave);
- DisposeRgn (dragContent);
- }
-
- short doHit (short varCode, WindowPeek theWindow, Point where)
-
- {
- Rect r;
-
-
- if (theWindow -> hilited) {
-
- getCloseRect (varCode, theWindow, &r);
- if (PtInRect (where, &r))
- return (wInGoAway);
- }
-
- getDragRect (varCode, theWindow, &r);
- if (PtInRect (where, &r))
- return (wInDrag);
-
- return (wInContent);
- }
-
- pascal long main (short varCode, WindowPeek theWindow, short message, long param)
-
- {
- long oldA4 = SetCurrentA4 ();
- short retVal = 0;
-
- switch (message) {
-
-
- case (wDraw) :
- if (param == wInGoAway) {
- drawCloseBox (varCode, theWindow, true);
- } else
- doDraw (varCode, theWindow, param);
- break;
-
- case (wHit) :
- retVal = doHit (varCode, theWindow, *((Point*)¶m));
- break;
-
- case (wCalcRgns) :
- calcRgns (varCode, theWindow);
- break;
-
- case (wNew) :
- theWindow -> dataHandle = NewHandleClear (0);
- break;
-
- case (wDispose) :
- DisposeHandle (theWindow -> dataHandle);
- break;
-
- }
-
- SetA4 (oldA4);
- return (retVal);
- }